package com.yuezhi.consumer.config;

import com.yuezhi.consumer.constant.QueueConstant;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RpcConfig {
    /**
     * 设置消息队列发送RPC队列
     */
    @Bean
    Queue rpcQueueSend() {
        return new Queue(QueueConstant.RPC_QUEUE_ONE);
    }

    /**
     * 设置RPC返回队列
     */
    @Bean
    Queue rpcQueueReply() {
        return new Queue(QueueConstant.RPC_QUEUE_TWO);
    }

    /**
     * 设置RPC交换机
     */
    @Bean
    TopicExchange rpcExchange() {
        return new TopicExchange(QueueConstant.RPC_EXCHANGE);
    }

    /**
     * 请求队列与交换机绑定
     */
    @Bean
    Binding rpcBindingSend() {
        return BindingBuilder.bind(rpcQueueSend()).to(rpcExchange()).with(QueueConstant.RPC_QUEUE_ONE);
    }

    /**
     * 返回队列与交换机绑定
     */
    @Bean
    Binding rpcBindingReply() {
        return BindingBuilder.bind(rpcQueueReply()).to(rpcExchange()).with(QueueConstant.RPC_QUEUE_TWO);
    }

}
